package com.yuer.rpc.rmi;

import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;

/**
 * 服务器端实现远程接口
 * 必须要竭诚UnicastRemoteObject
 */
public class RemoteEmplyerCallServiceImpl extends UnicastRemoteObject implements RemoteEmployerCallService{

    private int commitIndex;// 第几次体提交

    private HashMap<Integer,CoddingDetailModel> coddingDetailModelHashMap = new HashMap<>();

    protected RemoteEmplyerCallServiceImpl() throws RemoteException {
        for (int i= 0 ; i< 100; i++){
            CoddingDetailModel coddingDetailModel = new CoddingDetailModel();
            commitIndex = i+1;
            coddingDetailModel.setCommitId(commitIndex);
            coddingDetailModel.setCommitMsg(String.format("this is the %d time to commit code",commitIndex));
            coddingDetailModelHashMap.put(commitIndex,coddingDetailModel);
        }
    }


    @Override
    public void wirteCoding() throws RemoteException {
        System.out.println("我正在远程写代码");
    }

    @Override
    public CoddingDetailModel getRemoteCodeDetail(int i)throws RemoteException  {
        return  coddingDetailModelHashMap.get(i);
    }
}
